{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-09-07T13:56:02.945868Z",
     "start_time": "2025-09-07T13:56:02.934048Z"
    }
   },
   "source": [
    "# Series创建\n",
    "import pandas as pd\n",
    "s = pd.Series([1,2,3,4,5])\n",
    "print(s)\n",
    "# 创建索引---自定义\n",
    "s = pd.Series([1,2,3,4,5], index=['a','b','c','d','e'])\n",
    "print(s)\n",
    "\n",
    "# 定义name\n",
    "s = pd.Series([1,2,3,4,5], index=['a','b','c','d','e'], name='月份')\n",
    "print(s)"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0    1\n",
      "1    2\n",
      "2    3\n",
      "3    4\n",
      "4    5\n",
      "dtype: int64\n",
      "a    1\n",
      "b    2\n",
      "c    3\n",
      "d    4\n",
      "e    5\n",
      "dtype: int64\n",
      "a    1\n",
      "b    2\n",
      "c    3\n",
      "d    4\n",
      "e    5\n",
      "Name: 月份, dtype: int64\n"
     ]
    }
   ],
   "execution_count": 3
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-07T14:01:00.192057Z",
     "start_time": "2025-09-07T14:01:00.177278Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 通过字典来创建\n",
    "s = pd.Series({'A':1,'B':2,'C':3,'D':4,'E':5})\n",
    "print(s)\n",
    "\n",
    "s1 = pd.Series(s, index=['A','D'], name='月份') # 从s中创建s1，根据索引\n",
    "print(s1)\n",
    "\n",
    "print(s1.name)"
   ],
   "id": "b65088e8458452fe",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A    1\n",
      "B    2\n",
      "C    3\n",
      "D    4\n",
      "E    5\n",
      "dtype: int64\n",
      "A    1\n",
      "D    4\n",
      "Name: 月份, dtype: int64\n",
      "月份\n"
     ]
    }
   ],
   "execution_count": 8
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
